package com.tudouji.project.produce.controller;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.tudouji.common.utils.sql.SqlUtil;
import com.tudouji.framework.web.page.PageDomain;
import com.tudouji.framework.web.page.TableSupport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.produce.domain.Whinapply;
import com.tudouji.project.produce.service.IWhinapplyService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 入库申请单Controller
 *
 * @author tudouji
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/produce/whinapply")
public class WhinapplyController extends BaseController {
    @Autowired
    private IWhinapplyService whinapplyService;

    /**
     * 导出入库申请单列表
     */
    @PreAuthorize("@ss.hasPermi('produce:whinapply:export')")
    @Log(title = "入库申请单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Whinapply whinapply, String status, String functionType) {
        List<Whinapply> list = whinapplyService.selectWhinapplyList(whinapply,status,functionType);
        ExcelUtil<Whinapply> util = new ExcelUtil<Whinapply>(Whinapply.class);
        return util.exportExcel(list, "whinapply");
    }

    /**
     * 获取入库申请单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(whinapplyService.selectWhinapplyById(id));
    }

    /**
     * 新增入库申请单
     */
    @PreAuthorize("@ss.hasPermi('produce:whinapply:add')")
    @Log(title = "入库申请单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Whinapply whinapply) {
        return toAjax(whinapplyService.insertWhinapply(whinapply));
    }

    /**
     * 修改入库申请单
     */
    @PreAuthorize("@ss.hasPermi('produce:whinapply:edit')")
    @Log(title = "入库申请单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Whinapply whinapply) {
        return toAjax(whinapplyService.updateWhinapply(whinapply));
    }

    /**
     * 删除入库申请单
     */
    @PreAuthorize("@ss.hasPermi('produce:whinapply:remove')")
    @Log(title = "入库申请单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) {
        return toAjax(whinapplyService.deleteWhinapplyByIds(guids));
    }

    @GetMapping("/getWhinapplyInfo")
    public AjaxResult getWhinapplyInfo(Long pickinglistid,@RequestParam(required = false) String productflag){
        return whinapplyService.getWhinapplyInfo(pickinglistid,productflag);
    }

    @GetMapping("/getSpeByproduct")
    public AjaxResult getSpeByproduct(String productid,String type,String types,String stats){
        return whinapplyService.getSpeByproduct(productid,type,types,stats);
    }

    /**
     * 新增入库申请单
     */
    @Log(title = "入库申请单", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Whinapply whinapply,Long taskId,String fileIds) {
        return whinapplyService.save(whinapply,taskId,fileIds);
    }

    /**
     * 查询入库申请单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Whinapply whinapply, String status, String functionType) {
        startPage();
        List<Whinapply> list = whinapplyService.selectWhinapplyList(whinapply,status,functionType);
        return getDataTable(list);
    }



    @Log(title = "删除质检单", businessType = BusinessType.INSERT)
    @GetMapping("/delQaform")
    public AjaxResult delQaform(Long taskid, Long id, String opinion, String fileIds) {
        return whinapplyService.delQaform(id, fileIds, opinion, taskid);
    }

    @Log(title = "审批", businessType = BusinessType.OTHER)
    @PostMapping("/approval")
    public AjaxResult approval(Long taskid, Long id, String opinion, String fileIds) {
        return whinapplyService.approval(id, fileIds, opinion, taskid);
    }
    @Log(title = "拒绝", businessType = BusinessType.OTHER)
    @PostMapping("/refuse")
    public AjaxResult refuse(Long taskid, Long id, String opinion, String fileIds, Long refuseNodeid, Long backUserid) {
        return whinapplyService.refuse(id, fileIds, opinion, taskid, refuseNodeid, backUserid);
    }


    @Log(title = "删除",  businessType= BusinessType.DELETE)
    @PostMapping("/del/{id}")
    public AjaxResult del(@PathVariable("id") Long id) {
        return whinapplyService.del(id);
    }


}
